#@layout()
#define script()
<script>

    $('.del-action').on('click', function () {
        if (confirm('确定要删除该分类吗？删除后不可恢复')) {
            var id = $(this).attr("data-id");
            ajaxGet("#(CPATH)/admin/article/doCategoryDel/" + id);
        }
    });

    $(".tflag").each(function () {
        $(this).on('click', function () {
            $("#flag").val($(this).text());
        })
    });

    $(".dept").change(function () {
        var isChecked = $(this).is(':checked');
        if (isChecked) {
            setParentChecked($(this).attr("data-pid"));
        }
        //not checked
        else {
            setChildUnCheck($(this).attr("id"));
        }
    });

    function setParentChecked(parentId) {
        if (parentId && parentId != "dept0") {
            var pElement = $("#" + parentId);
            pElement.prop("checked", true);
            setParentChecked(pElement.attr("data-pid"))

        }
    }

    function setChildUnCheck(parentId) {
        if (parentId && parentId != "dept0") {
            var childElement = $("input[data-pid='" + parentId + "']");
            childElement.prop("checked", false);
            setChildUnCheck(childElement.attr("id"))
        }
    }


</script>
#end
#define content()
<section class="content-header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-6">

                <div class="row mb-2">
                    <div class="col-sm-12">
                        <h1>
                            文章分类
                            <small data-toggle="tooltip" title="" data-placement="right"
                                   data-trigger="hover"><i class="nav-icon far fa-question-circle"></i></small>
                            <small> 首页 / 文章 / 文章分类</small>
                        </h1>
                    </div>
                </div>
            </div>
        </div>

    </div><!-- /.container-fluid -->
</section>

<section class="content">

    <div class="row">
        <div class="col-lg-5">
            <div class="card card-outline card-primary">
                <!-- form start -->
                <form class=" form-setting autoAjaxSubmit" autocomplete="off"
                      action="#(CPATH)/admin/article/doCategorySave"
                      data-ok-href="#(CPATH)/admin/article/category"
                      data-ok-message="文章分类保存成功"
                      method="post">
                    <input type="hidden" name="category.id" value="#(category.id ??)">
                    <input type="hidden" name="category.type" value="category">
                    <div class="card-body">
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label"><span class="text-danger mr-2">*</span> 名称 </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" placeholder="取个适合的分类名称..." required
                                       value="#(category.title ??)" name="category.title">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label"><span class="text-danger mr-2">*</span> 父级</label>

                            <div class="col-sm-9">
                                <select class="form-control" name="category.pid">
                                    #if(category && category.pid == 0)
                                    <option value="0" selected>顶级</option>
                                    #else
                                    <option value="0">顶级</option>
                                    #end

                                    #for(c : categories)
                                    #if(category && category.pid == c.id)
                                    <option value="#(c.id)" selected>#(c.layerString) #(c.title)</option>
                                    #elseif(category && (category.id == c.id || category.isMyChild(c.id)))
                                    <option value="#(c.id)" disabled>#(c.layerString) #(c.title)</option>
                                    #else
                                    <option value="#(c.id)">#(c.layerString) #(c.title)</option>
                                    #end
                                    #end
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label"><span class="text-danger mr-2">*</span> 固定连接 </label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" placeholder="固定连接会显示在网址上..." required
                                       value="#(category.slug ??)" name="category.slug">
                                <p class="text-muted"> 此文章分类的 URL 地址为：<br/><span class="domainSpan">#option('web_domain')</span>/article/category/<span
                                        style="color: red">固定连接</span></p>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">排序</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" placeholder="此分类排序的序号"
                                       value="#(category.order_number ??)"
                                       name="category.order_number">
                                <p class="text-muted"> 越小的数字越靠前，只在同级分类上影响。 </p>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">内容</label>
                            <div class="col-sm-9">
                                    <textarea rows="3" class="form-control"
                                              placeholder="..."
                                              name="category.content">#(category.content ??)</textarea>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">摘要</label>
                            <div class="col-sm-9">
                                    <textarea rows="3" class="form-control"
                                              placeholder="..."
                                              name="category.summary">#(category.summary ??)</textarea>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">图标</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" placeholder="给该分类设置图标"
                                       value="#(category.icon ??)" name="category.icon">
                                <p class="text-muted"> 图标只用于前台显示，是否显示决定于模板。</p>
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">标识</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" placeholder="展示标识"
                                       value="#(category.flag ??)" name="category.flag" id="flag">
                                #if(flags && flags.size() > 0)
                                <p class="text-muted">当前模板支持的展示标识有：
                                    #for(flag : flags ??)
                                    <a href="javascript:;" class="tflag">#(flag)</a>
                                    #end
                                </p>
                                #end
                            </div>
                        </div>


                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">模板</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="category.style">
                                    <option value="">默认（artlist.html）</option>
                                    #for(style : styles)
                                    <option value="#(style)" #selectedIf(category && category.style== style)>
                                        artlist_#(style).html
                                    </option>
                                    #end
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">是否推荐</label>
                            <div class="col-sm-9">
                                <input type="checkbox" class="switchery" data-for="with_recommend" #checkedIf(category && category.with_recommend ??)>
                                <input type="hidden" id="with_recommend" name="category.with_recommend" value="false">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">是否置顶</label>
                            <div class="col-sm-9">
                                <input type="checkbox" class="switchery" data-for="with_top" #checkedIf(category && category.with_top ??)>
                                <input type="hidden" id="with_top"  name="category.with_top" value="false">
                            </div>

                        </div>

                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">显示到菜单</label>
                            <div class="col-sm-9">
                                <input type="checkbox" class="switchery" data-for="displayInMenu"
                                       #checkedIf(isDisplayInMenu)>
                                <input type="hidden" id="displayInMenu" name="displayInMenu" value="false">
                            </div>
                        </div>

                        <!--装饰和SEO_start-->
                        <div class="accordion">
                            <div class="card " style="box-shadow: none;">
                                <div class="card-header pl-2 border-bottom-light">
                                    <button type="button" class="btn btn-tool w-100  d-flex justify-content-between" data-toggle="collapse" data-target="#collapseOne">
                                        <h6 class="text-dark">装饰</h6>
                                        <span class="text-dark-50"><i class="fa fa-chevron-down" ></i></span>
                                    </button>
                                </div>
                                <div class="collapse" id="collapseOne">
                                    <div class="card-body p-4" >
                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label">装饰图</label>
                                            <div class="col-sm-9">
                                                <div class="jpress-image-browser">
                                                    <input type="hidden" name="category.ornament" value="#(category.ornament ??)"/>
                                                    <img src="#(category.ornament ?? (CPATH + '/static/commons/img/nothumbnail.jpg'))">
                                                    <div class="image-action">
                                                        <a class="image-delete"> <i class="fa fa-trash"></i></a>
                                                        <a class="image-edit"> <i class="fa fa-edit"></i></a>
                                                    </div>
                                                </div>
                                                <p class="text-muted"> </p>
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label">缩略图</label>
                                            <div class="col-sm-9">
                                                <div class="jpress-image-browser">
                                                    <input type="hidden" name="category.thumbnail" value="#(category.thumbnail ??)"/>
                                                    <img src="#(category.thumbnail ?? (CPATH + '/static/commons/img/nothumbnail.jpg'))">
                                                    <div class="image-action">
                                                        <a class="image-delete"> <i class="fa fa-trash"></i></a>
                                                        <a class="image-edit"> <i class="fa fa-edit"></i></a>
                                                    </div>
                                                </div>
                                                <p class="text-muted"> </p>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- /.card-body -->
                            </div>
                            <div class="card " style="box-shadow: none;">
                                <div class="card-header pl-2 border-bottom-light">
                                    <button type="button" class="btn btn-tool w-100  d-flex justify-content-between" data-toggle="collapse" data-target="#collapseTwo">
                                        <h6 class="text-dark">SEO</h6>
                                        <span class="text-dark-50"><i class="fa fa-chevron-down" ></i></span>
                                    </button>
                                </div>
                                <div class="collapse" id="collapseTwo">
                                    <div class="card-body p-4" >
                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label">标题</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" placeholder="SEO标题"
                                                       name="category.meta_title"
                                                       value="#(category.meta_title ??)">
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label">描述</label>

                                            <div class="col-sm-9">
                                    <textarea rows="3" class="form-control"
                                              placeholder="此内容会显示在搜索引擎的列表描述上..."
                                              name="category.meta_description">#(category.meta_description ??)</textarea>
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label">关键字</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" placeholder="多个关键字用逗号隔开"
                                                       name="category.meta_keywords"
                                                       value="#(category.meta_keywords ??)">
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- /.card-body -->
                            </div>
                        </div>

                        <!-- 装饰和SEO_end-->


                        #hasPermission("modify_article_category_department")
                        <h4 class="form-header">部门权限</h4>
                        <div class="form-group row">
                            <div class="offset-1 col-sm-11">
                                <div class="card-body">
                                    <div class="form-group">
                                        <input type="hidden" name="departmentIds" value="1"/>
                                        #for(department : departments)
                                        <div>
                                            <label>
                                                #for(i = 0; i < department.layerNumber; i++)
                                                &nbsp;&nbsp;
                                                #end

                                                <input class="dept" type="checkbox" id="dept#(department.id)"
                                                       data-pid="dept#(department.parent.id ?? 0)" name="departmentIds"
                                                       value="#(department.id)" #checkedIf(department.isCheck ||
                                                       department.id== 1) #disabledIf(department.id== 1)/>

                                                #(department.name ??)
                                            </label>
                                        </div>
                                        #else
                                        暂无部门信息
                                        #end
                                    </div>
                                </div>
                            </div>
                        </div>
                        #end

                        <h4 class="form-header">审核流程</h4>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">审核流程</label>
                            <div class="col-sm-9">
                                <div class="input-group">
                                    <input type="hidden" class="clear" name="category.flow_template_id" id="flowId" value="#(flowTemplate.id ??)">
                                    <input type="text" class="form-control" placeholder="请选择审核流程" readonly="" id="flowTitle" name="flowTitle" value="#(flowTemplate.title ??)">
                                    <div class="form-control-clear d-none"><i class="fas fa-times"></i></div>
                                    <div class="input-group-append">
                                        <button class="btn input-group-text" type="button" open-type="layer" data-layer-title="请选择要绑定的审核流程"
                                                data-layer-content="#(CPATH)/admin/flow/template/select"
                                                data-layer-binds="#flowTitle:title,#flowId:id"><i class="fas fa-search"></i></button>
                                    </div>
                                </div>

                            </div>
                        </div>


                    </div>
                    <!-- /.card-body -->
                    <div class="card-footer">
                        <div class="offset-sm-2 col-sm-10 submit-block">
                            <div class="card-submit">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </div>
                    <!-- /.card-footer -->
                </form>
            </div>
        </div>
        <div class="col-lg-7">
            <div class="card card-outline card-primary">


                <div class="card-body p-0  ">

                    <table class="table table-striped">
                        <tbody>
                        <tr>
                            <th style="width: 40%">标题</th>
                            <th>固定链接</th>
                            <th>描述</th>
                            <th>排序</th>
                        </tr>
                        #for(category : categories)
                        <tr>
                            <td>
                                <strong>
                                    <a href="#(category.url ??)" target="_blank">
                                        #(category.layerString) #(category.title)
                                    </a>
                                    （#(category.count ?? 0)）
                                </strong>
                                <div class="jp-action-card">
                                    <div class="jp-action-body">
                                        <a href="#(CPATH)/admin/article/category/#(category.id)">编辑</a>
                                        #staticize(category.url,"|") |
                                        <a href="javascript:;" class="del-action red-action"
                                           data-id="#(category.id)">删除</a> |
                                        <a href="#(category.url ??)" target="_blank" class="red-action">访问</a>
                                    </div>
                                </div>
                            </td>
                            <td>#(category.slug ??)</td>
                            <td>#(category.content ??)</td>
                            <td>#(category.order_number ??)</td>
                        </tr>
                        #else
                        <tr class="nodata">
                            <td colspan="999">暂无数据</td>
                        </tr>
                        #end
                        </tbody>
                    </table>
                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                    <div class="row">
                        <div class="col-sm-12">
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.card -->
        </div>
    </div>
</section>


#end
